<html>
<head><meta charset="utf-8"><title>When do proc macros run? · t-compiler/performance · Zulip Chat Archive</title></head>
<h2>Stream: <a href="https://rust-lang.github.io/zulip_archive/stream/247081-t-compiler/performance/index.html">t-compiler/performance</a></h2>
<h3>Topic: <a href="https://rust-lang.github.io/zulip_archive/stream/247081-t-compiler/performance/topic/When.20do.20proc.20macros.20run.3F.html">When do proc macros run?</a></h3>

<hr>

<base href="https://rust-lang.zulipchat.com">

<head><link href="https://rust-lang.github.io/zulip_archive/style.css" rel="stylesheet"></head>

<a name="205196960"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/247081-t-compiler/performance/topic/When%20do%20proc%20macros%20run%3F/near/205196960" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> njn <a href="https://rust-lang.github.io/zulip_archive/stream/247081-t-compiler/performance/topic/When.20do.20proc.20macros.20run.3F.html#205196960">(Jul 28 2020 at 04:20)</a>:</h4>
<p>rustc has a proc macro that generates the table of static symbols. There's <a href="https://github.com/rust-lang/rust/blob/ac48e62db85e6db4bbe026490381ab205f4a614d/src/librustc_macros/src/symbols.rs#L192">an <code>eprintln!</code>statement</a> at its end that you can uncomment if you want to see the generated code.</p>



<a name="205196968"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/247081-t-compiler/performance/topic/When%20do%20proc%20macros%20run%3F/near/205196968" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> njn <a href="https://rust-lang.github.io/zulip_archive/stream/247081-t-compiler/performance/topic/When.20do.20proc.20macros.20run.3F.html#205196968">(Jul 28 2020 at 04:21)</a>:</h4>
<p>When I run <code>./x.py check</code>, that <code>eprintln</code> statement prints stuff out every single time. Even if I haven't changed the code.</p>



<a name="205196971"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/247081-t-compiler/performance/topic/When%20do%20proc%20macros%20run%3F/near/205196971" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> njn <a href="https://rust-lang.github.io/zulip_archive/stream/247081-t-compiler/performance/topic/When.20do.20proc.20macros.20run.3F.html#205196971">(Jul 28 2020 at 04:21)</a>:</h4>
<p>That seems wrong. Is it wrong?</p>



<a name="205197030"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/247081-t-compiler/performance/topic/When%20do%20proc%20macros%20run%3F/near/205197030" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> njn <a href="https://rust-lang.github.io/zulip_archive/stream/247081-t-compiler/performance/topic/When.20do.20proc.20macros.20run.3F.html#205197030">(Jul 28 2020 at 04:22)</a>:</h4>
<p>The output from a nothing-changed <code>./x.py check</code> run is like this:</p>
<div class="codehilite"><pre><span></span><code>Submodules updated in 0.05 seconds
    Finished dev [unoptimized + debuginfo] target(s) in 0.10s
Checking rustdoc artifacts (x86_64-unknown-linux-gnu -&gt; x86_64-unknown-linux-gnu)
Checking clippy artifacts (x86_64-unknown-linux-gnu -&gt; x86_64-unknown-linux-gnu)
Checking std artifacts (x86_64-unknown-linux-gnu -&gt; x86_64-unknown-linux-gnu)
    Finished release [optimized + debuginfo] target(s) in 0.10s
Checking compiler artifacts (x86_64-unknown-linux-gnu -&gt; x86_64-unknown-linux-gnu)
&lt;... eprintln output...&gt;
    Finished release [optimized + debuginfo] target(s) in 0.15s
Checking rustdoc artifacts (x86_64-unknown-linux-gnu -&gt; x86_64-unknown-linux-gnu)
    Finished release [optimized + debuginfo] target(s) in 0.11s
Checking clippy artifacts (x86_64-unknown-linux-gnu -&gt; x86_64-unknown-linux-gnu)
    Finished release [optimized + debuginfo] target(s) in 0.10s
Build completed successfully in 0:00:52
</code></pre></div>



<a name="205197834"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/247081-t-compiler/performance/topic/When%20do%20proc%20macros%20run%3F/near/205197834" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> njn <a href="https://rust-lang.github.io/zulip_archive/stream/247081-t-compiler/performance/topic/When.20do.20proc.20macros.20run.3F.html#205197834">(Jul 28 2020 at 04:45)</a>:</h4>
<p>And with <code>./x.py build --stage 2 src/rustc</code> it runs twice every time, once per stage</p>



<a name="205199953"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/247081-t-compiler/performance/topic/When%20do%20proc%20macros%20run%3F/near/205199953" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Eric Huss <a href="https://rust-lang.github.io/zulip_archive/stream/247081-t-compiler/performance/topic/When.20do.20proc.20macros.20run.3F.html#205199953">(Jul 28 2020 at 05:42)</a>:</h4>
<p>I think in this case, the output is cached by Cargo, and replayed during each build.  I think you can use stdout (<code>println</code>) to avoid the cache if that's a problem.</p>



<a name="205201445"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/247081-t-compiler/performance/topic/When%20do%20proc%20macros%20run%3F/near/205201445" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> njn <a href="https://rust-lang.github.io/zulip_archive/stream/247081-t-compiler/performance/topic/When.20do.20proc.20macros.20run.3F.html#205201445">(Jul 28 2020 at 06:18)</a>:</h4>
<p>ah</p>



<a name="205201573"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/247081-t-compiler/performance/topic/When%20do%20proc%20macros%20run%3F/near/205201573" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> njn <a href="https://rust-lang.github.io/zulip_archive/stream/247081-t-compiler/performance/topic/When.20do.20proc.20macros.20run.3F.html#205201573">(Jul 28 2020 at 06:21)</a>:</h4>
<p>Yes, using <code>println</code> avoids the repetition. Makes sense, thanks!</p>



<hr><p>Last updated: Aug 07 2021 at 22:04 UTC</p>
</html>